package com.persondemo.videoappliction.ui.publish.presenter;

import com.persondemo.videoappliction.bean.PutBean;
import com.persondemo.videoappliction.bean.UpimgBean;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.BaseObserver;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.publish.contract.PutContract;

import javax.inject.Inject;

import okhttp3.MultipartBody;

/**
 * Created by Administrator on 2018/4/25.
 */

public class PutPresenter extends BasePresenter<PutContract.View> implements PutContract.Presenter {
    BaseApi baseApi;

    @Inject
    public PutPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void upimgdata(MultipartBody.Part file) {
        baseApi.upimgdata(file)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<UpimgBean>() {
                    @Override
                    public void onSuccess(UpimgBean upimgBean) {
                        mView.imgdata(upimgBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }

    @Override
    public void putdata(String comment, String device, String img, String type) {
        baseApi.putdatas(comment, device, img, type)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<PutBean>() {
                    @Override
                    public void onSuccess(PutBean putBean) {
                        mView.loadput(putBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
}
